<template>
  <div class="mv_list" v-if="mvList.length">
    <div class="mv_first">
      <div class="mv_first_item" v-for="(item, index) in mvList" :key="index" @mouseenter="handleEnter(index)" @mouseleave="handleLeave" @click="handleMvItme(item.id)">
        <div class="mv_info">
          <div class="mv_info_top">
            <i class="iconfont icon-shipin"></i>
            <span>{{ item.playCount.toString().slice(0, 2) + '万' }}</span>
          </div>
          <img :src="item.cover || item.picUrl" alt="" />
          <transition name="playlist-opacity">
            <div class="mv-item-play" v-show="index == mvIndex">
              <i class="iconfont icon-icon_play"></i>
            </div>
          </transition>
        </div>
        <div class="mv_v">
          <span class="mv_title">{{ item.name }}</span>
          <span class="mv_name">{{ item.artistName }}</span>
        </div>
      </div>
    </div>
  </div>
</template>

<script>
export default {
  name: 'mvlist',
  data() {
    return {
      mvIndex: null
    }
  },
  props: {
    mvList: {
      type: Array,
      default: () => []
    }
  },
  methods: {
    handleEnter(index) {
      this.mvIndex = index
    },
    handleLeave() {
      this.mvIndex = null
    },
    handleMvItme(id) {
      this.$router.push('/mvdetail/' + id)
    }
  }
}
</script>

<style lang="less" scoped>
.mv_list {
  width: 100%;
  padding: 20px 0;
  .mv_first {
    width: 100%;
    display: flex;
    flex-wrap: wrap;
    justify-content: space-between;
    .mv_first_item {
      width: 23%;
      padding-bottom: 24px;
      cursor: pointer;
      .mv_info {
        width: 100%;
        position: relative;
        overflow: hidden;
        border-radius: 6px;
        .mv_info_top {
          position: absolute;
          top: 0;
          right: 0;
          width: 32%;
          height: 30px;
          color: #fff;
          display: flex;
          justify-content: center;
          align-items: center;
          background: linear-gradient(to right, rgba(0, 0, 0, 0), rgba(0, 0, 0, 0.3));
          span {
            font-size: 14px;
          }
        }
        img {
          border-radius: 6px;
          width: 100%;
          height: 130px;
        }
        .mv-item-play {
          width: 40px;
          height: 40px;
          position: absolute;
          left: 50%;
          top: 50%;
          transform: translate(-50%, -50%);
          border-radius: 50%;
          background: rgba(255, 255, 255, 0.5);
          display: flex;
          justify-content: center;
          align-items: center;
          .icon-icon_play {
            font-size: 24px;
            color: var(--main-color);
          }
        }
      }
      .mv_v {
        width: 100%;
        height: 30px;
        font-size: 14px;
        .mv_title {
          color: #333;
          font-weight: 600;
        }
        .mv_name {
          padding-left: 10px;
          color: var(--primary);
        }
      }
    }
  }
}
.playlist-opacity-enter-active {
  animation: fadeOut var(--animation-base-time) reverse;
}
.playlist-opacity-enter-leave {
  animation: fadeOut var(--animation-base-time);
}
</style>
